class student {
    public String name;
    public int age;

    public student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
public class Test {

    public static void main(String[] args) {
        //字符串截取
        String str = "abcdef";
        String ret = str.substring(2);//截取2后面的字符串
        System.out.println(ret);
        System.out.println(str.substring(1,3));//截取一个范围内的字符串

    }
    public static void main9(String[] args) {
        //字符串拆分
        String str = "www.aaa.com.aaa.bbbb";
        String[] ret = str.split("\\.",'1');
        for (int i = 0; i < ret.length; i++) {
            System.out.println(ret[i]);
        }
        String str2 = "111 222 333 444 555";
        String[] tmp = str2.split(" ",2);
        for (int i = 0; i < tmp.length; i++) {
            System.out.println(tmp[i]);
        }
    }
    public static void main8(String[] args) {
        //字符串替换
        String str = "abcdabcdabcd";
        String ret = str.replace('a','x');
        System.out.println(ret);
        //替换一组字符串
        System.out.println(str.replace("abc","xxxxxxx"));
        System.out.println(str.replaceAll("ab","##"));
        //值替换第一个
        System.out.println(str.replaceFirst("abc","####"));


    }
    public static void main7(String[] args) {
        //字符串转数组
        String str = "hello";
        char[] arr = str.toCharArray();
        for (char x:arr) {
            System.out.println(x);
        }

        //格式化输出
        String str2 = String.format("%d---%d---%d",2018,6,18);
        System.out.println(str2);




    }
    public static void main6(String[] args) {
        //字符转化
        //1.整数转字符串
        String str = String.valueOf(123);
        System.out.println(str);
        System.out.println(new student("张三",18));
        //2.字符串转整数
        int a = Integer.parseInt("999");
        System.out.println(a);
        System.out.println("---------");
        //大小写转化
        String str2 = "hello";
        String str3 = str2.toUpperCase();
        System.out.println(str3);
        String str4 = str3.toLowerCase();
        System.out.println(str4);

    }
    public static void main5(String[] args) {
        //int lastIndexOf(int ch)
        String str  = "abcdef";
        System.out.println(str.lastIndexOf('f'));//从后往前找
        System.out.println(str.lastIndexOf('c',3));//指定位置

    }
    public static void main4(String[] args) {
        //字符串查找
        //返回字符串对应下标的字符
        String str = "abcdef";
        char ch = str.charAt(2);//2下标的值
        System.out.println(ch);
        System.out.println("-------------");
        //indexOfd的三个方法
        //返回对应字符出现的下标位置
        int index = str.indexOf('d');
        System.out.println(index);
        //从指定位置开始
        System.out.println(str.indexOf('d',1));
        System.out.println(str.indexOf('d',3));

        System.out.println(str.indexOf("cd"));
        System.out.println("-----------");

    }
    public static void main3(String[] args) {
        String str1 = new String("hello");
        String str2 = new String("hello");
        System.out.println(str1==str2);//比较的是引用的地址
        System.out.println(str1.equals(str2));//比较是否相等

        String str3 = "abcd";
        String str4 = "abcdf";
        System.out.println(str3.compareTo(str4));//比较字符串大小

        //忽略大小写
        System.out.println(str1.equalsIgnoreCase(str2));
        System.out.println(str2.compareToIgnoreCase(str4));


    }
    public static void main2(String[] args) {
        String str1 = "hello";
        String str2 = "world";
        String str3 = str2;
        System.out.println(str2);
        System.out.println(str3);
        System.out.println("-----------");
        //求长度
        System.out.println(str2.length());
        //判空
        System.out.println(str2.isEmpty());
        String str4 = "";
        System.out.println(str4);

        String str5 = null;//这这种表示这个引用不指向对象，不是空的意思
    }
    public static void main1(String[] args) {
        String str = "I love you";
        System.out.println(str);

        String str2 = new String("love you too");
        System.out.println(str2);

        char[] arr = {'6','6','6'};
        String str3 = new String(arr);
        System.out.println(str3);

        Test test = new Test();
        System.out.println(test);
    }
}
